package com.hsxc.cdz.controller.appController;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hsxc.cdz.base.bean.MyUser;
import com.hsxc.cdz.mgmt.user.MyUserManager;

import net.sf.json.JSONObject;

/**
 * 接收App 关于用户的请求
 * @author 刘力文
 * 
 */
@Controller("myUser")
@RequestMapping("/app")
public class UserController {
	
	//==========================================================
	//注入service实例对象
	@Autowired
	private MyUserManager myUserManager;
	Logger logger = LoggerFactory.getLogger(UserController.class);
	
	//==========================================================
	//类私有常量
	private static final int SUCCESS = 0;
	private static final int ERR_DATA = 1;
	private static final int ERR_DEVICE = 2;
	private static final int FAILURE = 3;
	
	//==========================================================
	//处理请求
	/**
	 * 添加用户
	 * @param data 
	 * @return
	 */
	@RequestMapping(value="/user",method =RequestMethod.POST)
	public Object addUser(String data){
		JSONObject json = JSONObject.fromObject(data);
		logger.info(json.toString());
	    MyUser myUser = new MyUser();
	    myUserManager.insertOne(myUser);
		return null;
	}
	
	@RequestMapping(value="/user/{regName}",method =RequestMethod.DELETE)
	public Object deleteUser(@PathVariable("regName") String regName) {
		return null;
	}
	
	@RequestMapping(value="/user",method =RequestMethod.PUT)
	public Object updateUser(String data){
		JSONObject json = JSONObject.fromObject(data);
		logger.info(json.toString());
	    MyUser myUser = new MyUser();
	    myUserManager.updateUser(myUser);
		return null;
	}
	
	@RequestMapping(value="/user/{regName}",method =RequestMethod.GET)
	public Object getUserPoint(@PathVariable("regName") String regName) {
		return null;
	}
}
